#include "syscall.h"
#include "user.h"

void testFork();
void testExit1();

main ()
{	int i;
	int whichTest;
	Printf("Please choose which test to run:\n");
	Printf("test1: to test fork that will exit normally\n");
	Printf("test2: to fork too many threads\n");
	Printf("test3: to exec a simple file properly\n");
	Printf("test4: to test a file can exec another process\n");
	Printf("test5: to exec a file itself infinite\n");
	Printf("test6: to exec too many processes\n");
	Printf("test7: to fork a thread will exit abnormally\n");
	
	whichTest = InputInt();
	switch(whichTest){
		case 1:
		Printf("test1: to test fork that will exit normally\n");
		Fork(testFork);
		break;
		
		case 2:
		Printf("test2: to fork too many threads\n");
		for(i=0;i<205;i++)
			Fork(testFork);
		break;
		
		case 3:
		Printf("test3: to exec a simple file properly\n");
		Exec("../test/execTest3",sizeof("../test/execTest3"));
		break;
		
		case 4:
		Printf("test4: to test a file can exec another process\n");
		Exec("../test/execTest4",sizeof("../test/execTest4"));
		break;
		
		case 5:
		Printf("test5: to exec a file itself infinite\n");
		Exec("../test/execTest5",sizeof("../test/execTest5"));
		break;
		
		case 6:
		Printf("test6: to exec too many processes\n");
		for(i=0;i<10;i++)
			Exec("../test/execTest3",sizeof("../test/execTest3"));
		break;
		  
		case 7:
		/*Note that from the above we have tested processes as well as threads can exit normally, we only need to test some special cases*/
		Printf("test7: to fork a thread will exit abnormally\n");
		Fork(testExit1);
		break;
   }
  
  Exit(0);
  
}

void testFork()
{
	Printf("Fork a thread successfully\n");
	Printf("Fork finished\n");
	Exit(0);
}

void testExit1()
{
	Printf("will exit abnormally\n");
	Exit(1);
}